using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Googleboys.Inventa.Concept;

namespace Googleboys.Inventa.Main
{
	public partial class frmRental : Form
	{
		public frmRental(Person p, Ort o, Gegenstand g)
		{
			InitializeComponent();

			// Initialisierung
			_Person = p;
			_Ort = o;
			this.lblGegenstand.Text = g.Bezeichnung;

			if (g is Software)
				this.pctrebxGegenstand.Image = global::Googleboys.Inventa.Properties.Resources.icon4;
			else if (g is Hardware)
				this.pctrebxGegenstand.Image = global::Googleboys.Inventa.Properties.Resources.icon5;
			else if (g is Mobiliar)
				this.pctrebxGegenstand.Image = global::Googleboys.Inventa.Properties.Resources.icon1;
			else if (g is Buch)
				this.pctrebxGegenstand.Image = global::Googleboys.Inventa.Properties.Resources.icon3;



			// Buttons
			this.bttnOK.Click += OnOK;
			this.bttnAbbrechen.Click += OnAbbrechen;



			// Personen
			this.bndngSrcPersonen.DataSource = typeof (ItemList<Person>);
			this.bndngSrcPersonen.DataSource = InventarManager.GetPersonenList();
			this.lstbxPersonen.DataSource = this.bndngSrcPersonen;
			this.lstbxPersonen.SelectedValueChanged += OnPersonenSelectedValueChanged;
			
			// Vorauswahl
			if (bndngSrcPersonen.Count > 0)
			{
				_Person = (Person) this.bndngSrcPersonen[0];
			}



			// Orte
			this.bndngSrcOrte.DataSource = typeof (ItemList<Ort>);
			this.bndngSrcOrte.DataSource = InventarManager.GetOrteList();
			this.lstbxOrte.DataSource = this.bndngSrcOrte;
			this.lstbxOrte.SelectedValueChanged += OnOrteSelectedValueChanged;

			// Vorauswahl
			if (bndngSrcPersonen.Count > 0)
			{
				_Ort = (Ort)this.bndngSrcOrte[0];
			}
		}



		//
		// Form On-Events
		//
		#region Form On-Events

		private void OnOrteSelectedValueChanged(object sender, EventArgs e)
		{
			ListBox lb = sender as ListBox;

			_Ort = (Ort)this.bndngSrcOrte[lb.SelectedIndex];
		}

		private void OnPersonenSelectedValueChanged(object sender, EventArgs e)
		{
			ListBox lb = sender as ListBox;

			_Person = (Person)this.bndngSrcPersonen[lb.SelectedIndex];
		}

		private void OnOK(object sender, EventArgs e)
		{
			this.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.Close();
		}

		private void OnAbbrechen(object sender, EventArgs e)
		{
			this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.Close();
		}

		#endregion



		//
		// Properties
		//
		#region Properties

		public Ort Ort
		{
			get { return _Ort; }
			set { _Ort = value; }
		}

		public Person Person
		{
			get { return _Person; }
			set { _Person = value; }
		}

		#endregion



		//
		// Members
		//
		#region Members

		private Person _Person;
		private Ort _Ort;

		#endregion 
	}
}